<?php 
    ob_start();
    include("header.php");
    setTabIndex(2);
    createPage("Liga - Overzicht tornooien");
?>

<?
    mysql_connect(DB_SERVER, DB_USER, DB_PWD);
    mysql_select_db(DB_CATALOG);
    $result = mysql_query("SELECT ut.name, ut.date, ut.ref, u.user_id, c.clubname, concat( u.firstname, ' ', u.lastname ) AS author
        FROM uploaded_tournament ut
        JOIN user u ON u.user_id = ut.user_id
        LEFT JOIN club c ON c.club_id = u.club_id
        ORDER BY ut.upload_id DESC");

    $uploadedTournaments = array();
    while ($row = mysql_fetch_assoc($result)) {
        $uploadedTournament = new UploadedTournament();
        $uploadedTournament->user_id = $row['user_id'];
        $uploadedTournament->author = $row['author'];
        $uploadedTournament->club = $row['clubname'];
        $uploadedTournament->date = $row['date'];
        $uploadedTournament->name = $row['name'];
        $uploadedTournament->ref = $row['ref'];
        $url = $uploadedTournament->user_id."/".$uploadedTournament->ref;
        
        //if ( isValidURL($url) ) {
            $uploadedTournament->ref = $url;
        //} else {
            //$uploadedTournament->ref = "";
        //}
        array_push($uploadedTournaments, $uploadedTournament);
    }
?>


<?
$screen_res = 1900;
if(isset($_COOKIE["users_resolution"])) {
    $screen_res = $_COOKIE["users_resolution"];
    setcookie ("users_resolution", "", time() - 3600);
} else { //means cookie is not found set it using Javascript
?>
<script language="javascript">
<!--
writeCookie();

function writeCookie() 
{
 var today = new Date();
 var the_date = new Date("December 31, 2100");
 var the_cookie_date = the_date.toGMTString();
 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
 document.cookie=the_cookie
     
 //if(navigator.cookieEnabled) location = 'tornooien.php';
}
//-->
</script>
<?
}
?>



<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0" bgcolor="#FFFFFF">

    <tr>
        <td id="leftFiller" valign="top" height="100%" rowspan="3" bgcolor="#666666">
            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="8px">
                <tr><td>&nbsp;</td></tr>
            </table>
        </td>
        <td id="header" valign="top" width="100%">
            <table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#10425b">
                <tr>
                    <td bgcolor="#666666" width="70%">
                        <?php include("inc_title.html"); ?>
                    </td>
                    <td bgcolor="#666666" align="right" valign="top">&nbsp;

                    </td>
                </tr>
            </table>
            <table align="center" border="0" width="100%" height="90%" cellpadding="0" cellspacing="0" style="border-top:#BCDD10 4px solid;">
                <tr>
                    <?php include("inc_sublinks.php"); ?>
                </tr>
                <tr><td colspan="2" nowrap bgcolor="#BCDD10" height="4"><img src="/assets/images/spacer.gif" alt="" height="1" width="1"></td></tr>
                <tr>
                    <td>&nbsp;</td>
                    <td valign="top">
                        <table align="left" cellspacing="10" width="100%">
                            <tr>
                                <td width="50%" valign="top">
                                    <? if ($screen_res > 1280) { ?>
                                    <iframe src="http://www.google.com/calendar/embed?height=600&amp;wkst=2&amp;bgcolor=%23FFFFFF&amp;src=06pgoud782d298q15ogja4ca74%40group.calendar.google.com&amp;color=%23182C57&amp;ctz=Europe%2FBrussels" style=" border-width:0 " width="800" height="600" frameborder="0" scrolling="no"></iframe>
                                    <? } else { ?>
                                    <iframe src="http://www.google.com/calendar/embed?height=600&amp;wkst=2&amp;bgcolor=%23FFFFFF&amp;src=06pgoud782d298q15ogja4ca74%40group.calendar.google.com&amp;color=%23182C57&amp;ctz=Europe%2FBrussels" style=" border-width:0 " width="600" height="500" frameborder="0" scrolling="no"></iframe>
                                    <? } ?>
                                </td>
                                <td width="50%" valign="top">
                                    <span class="blackHeaderLarge">Tornooikalender</span>
                                    <br>&nbsp;<br>
                                    U kan hier nakijken wanneer welke tornooien plaatsvinden. U kan door de agenda bladeren (week, maand of agendalijst) en door te klikken op de tornooilabels
                                    krijgt u gedetailleerde informatie.
                                    <br/>&nbsp;<br/>
                                    Onze clubs zetten zelf hun tornooi-informatie hierop via <a href="http://www.google.com/calendar" target="_blank">Google Calendar</a>. Dit is zeer eenvoudig, indien
                                    uw club ook toegang tot deze feature wil, gelieve het google calendar adres (gmail) te sturen naar <a href="mailto:webmaster@schaakliga-antwerpen.info">de webmaster</a>.
                                    <br/>&nbsp;<br/>
                                    <? if ($screen_res > 1280) { ?>
                                    <img src="http://www.google.com/googlecalendar/images/learn_more.jpg" />
                                    <? } else { ?>
                                    <img src="http://www.google.com/googlecalendar/images/learn_more.jpg" width="80%" />
                                    <? } ?>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                <span class="blackHeaderLarge">Tornooiresultaten</span>
                                    <br>&nbsp;<br>
                                    Hier vindt u tornooien die door Antwerpse clubs zijn georganiseerd en op de ligasite 
                                    zijn geplaatst. Momenteel is er enkel support voor html-bestanden (bv. gegenereerd door
                                    PairTwo of SwissMaster).
                                    <?
                                        if (!isset($_SESSION['user'])) {
                                    ?>
                                    Bestaande accounteigenaars hebben nog geen rechten om deze bestanden up te
                                    loaden. Gelieve <a href="mailto:webmaster@schaakliga-antwerpen.info">mij te contacteren</a> 
                                    indien u uw eigen tornooiresultaten hier wil publiceren.
                                    <?
                                        } else {
                                    ?>
                                    Opmerking: u kan uw referentiepagina wijzigen in de upload-sectie, selecteer
                                    uw tornooi, wijzig de referentie en klik op "Doorsturen". Dit is bv. zeer handig
                                    als u de eerder opgeladen paring wil vervangen door de uitslagen.
                                    <?        
                                        }
                                    ?>
                                    
                                    <br>&nbsp;<br>
                                    <table align="left" border="0" width="90%" height="90%" cellpadding="2" cellspacing="0">
                                        <tr>
                                            <td width="10%"><strong>Datum</strong></td>
                                            <td width="30%"><strong>Naam</strong></td>
                                            <td width="20%"><strong>Club</strong></td>
                                            <td width="20%"><strong>Auteur</strong></td>
                                        </tr>
                                        <?
                                        foreach ($uploadedTournaments as $item) {
                                        ?>
                                        <tr>
                                            <td style="border-bottom:#DDDDDD solid 1px"><?=$item->date?></td>
                                        <?
                                            if (!empty($item->ref)) {
                                        ?>
                                            <td style="border-bottom:#DDDDDD solid 1px"><a href="upload/<?=$item->ref?>" target="_blank"><?=$item->name?></a></td>
                                        <?
                                            } else {
                                        ?>
                                            <td style="border-bottom:#DDDDDD solid 1px"><?=$item->name?> (geen geldige referentie, contacteer auteur)</td>
                                        <?
                                            }
                                        ?>
                                            
                                            <td style="border-bottom:#DDDDDD solid 1px"><?=$item->club?></td>
                                            <td style="border-bottom:#DDDDDD solid 1px"><?=$item->author?></td>
                                        </tr>
                                        <?
                                        }
                                        ?>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<?php include("footer.php") ?>